package com.fishery.customization.service.impl;

import com.fishery.customization.dao.UserLabelDao;
import com.fishery.customization.entity.OneLevelLabel;
import com.fishery.customization.entity.UserLabel;
import com.fishery.customization.service.UserLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;


@Service
public class UserLabelServiceImpl implements UserLabelService {

	@Autowired
	private UserLabelDao userLabelDao;

	@Override
	public String getCustomizedLabelsOfUserByUserId(String userId) {
		return userLabelDao.findCustomizedLabelsOfUserByUserId(userId);
	}


	@Override
	public boolean saveOrUpdateLabelsByUserIdAndBaseIdAndRole(UserLabel userLabel) {
		return userLabelDao.upsertLabelsByUserId(userLabel) > 0;
	}

	@Override
	public boolean removeLabelsByUserId(String userId) {
		return userLabelDao.deleteLabelsByUserId(userId) > 0;
	}

	@Override
	public boolean updateBaseRoleNameByBaseId(String baseId, String oldName, String newName) {
		return userLabelDao.updateBaseRoleNameByBaseId(baseId, oldName, newName) > 0;
	}

	@Override
	public boolean updateUserLabelsByBaseIdAndRole(String baseId, String role, Collection<OneLevelLabel> addOneLevelLabels, Collection<OneLevelLabel> deleteOneLevelLabels) {
		return userLabelDao.queryAndUpdate(baseId, role, addOneLevelLabels, deleteOneLevelLabels) > 0;
	}

	@Override
	public boolean updateOtherUsersLabelsOfBaseByBaseIdAndRole(String baseId, String exceptRole, Collection<OneLevelLabel> addOneLevelLabels, Collection<OneLevelLabel> deleteOneLevelLabels) {
		return userLabelDao.queryAndUpdateOthers(baseId, exceptRole, addOneLevelLabels, deleteOneLevelLabels) > 0;
	}


}
